home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 10
/
FM Towns Free Software Collection 10.iso
/
ms_dos
/
tool
/
dprint
/
dp_data.c
< prev
next >
Wrap
Text File
|
1994-08-11
|
5KB
|
265 lines
/*
8086|Printman/POSTCARD データ処理メニュー
Copyright (c) 1993,94 Delmonta
*/
#include<stdlib.h>
#include<farstr.h>
#include"dprint.h"
/*---------------------------------------------------------------------------*/
static void dp_insert(void)
{
unsigned i;
int ret[1];
static struct SHEETDAT sheet[1] =
{ {SHEET_VALUE1,"枚数",1,DUMMY,NULL}, };
if (Cardnum==MAXCARD)
{
dp_errmes("カードはこれ以上増やせません.");
return;
}
else if (Cardnum==0)
return;
sheet[0].max = MAXCARD-Cardnum;
ret[0] = 1;
if (!dp_sheetselect(SYSLINE_START,sheet,1,ret))
return;
for (i=Cardnum-1 ; (signed int)i>=(signed int)Cardpos ; i--)
{
dp_errmes("");
Card[i+ret[0]] = Card[i];
}
for (i=0 ; i<ret[0] ; i++)
{
if (!addcard(Cardpos+i)) /* 途中でメモリ不足になった場合 */
{
unsigned j;
printf("\033[17;1f%u blanks are allocated. \n",i);
for (j=0 ; j<Cardnum-Cardpos ; j--)
Card[Cardpos+i+j] = Card[Cardpos+ret[0]+j];
break;
}
}
Cardnum += i;
Changedflag = TRUE;
card_reshow(63);
dp_putcardnum();
}
/*---------------------------------------------------------------------------*/
static void dp_delete(void)
{
int s,e;
unsigned i,n;
if (!input_st_ed("削除",&s,&e))
return;
n = e - s + 1;
for ( i=s ; i<=e ; i++)
{
void farfree(void far *);
farfree(Card[i]);
Card[i] = Card[i+n];
}
Cardnum -= n;
if (Cardpos > Cardnum)
Cardpos = Cardnum;
Changedflag = TRUE;
card_reshow(63);
dp_putcardnum();
}
/*---------------------------------------------------------------------------*/
static enum SORTTYPE {SORT_UP=0,SORT_DOWN} Sort_type;
static int dpsort_sub(p,q)
struct POSTCARD far **p,far **q;
{
int a = (*p)->zipcode[0] - (*q)->zipcode[0];
if (a==0)
a = (*p)->zipcode[1] - (*q)->zipcode[1];
if (Sort_type==SORT_DOWN)
a = -a;
return a;
}
static void dp_sort(void)
{
static struct SHEETSEL select[2] =
{
{19,"昇順"},
{25,"降順"},
};
static struct SHEETDAT sheet[3] =
{
{SHEET_VALUE1,"開始位置",1,DUMMY,NULL},
{SHEET_VALUE1,"終了位置",SHEET_CREF(0),DUMMY,NULL},
{SHEET_SELECT,"順序",0,2,select},
};
int ret[3];
sheet[0].max = sheet[1].max = Cardnum;
ret[0] = 1;
ret[1] = Cardnum;
ret[2] = 0;
if (!iscardexist() || !dp_sheetselect(SYSLINE_START,sheet,3,ret))
return;
Sort_type = (enum SORTTYPE)ret[2];
qsort(Card+ret[0]-1,ret[1]-ret[0]+1,sizeof(Card[0]),
(int (*)(void *,void *))dpsort_sub);
card_reshow(63);
Changedflag = TRUE;
}
/*---------------------------------------------------------------------------*/
static int Find_zip[2];
static char far *Find_str;
static bool dpfind_sub(unsigned pos)
{
int i;
for (i=0 ; i<5 ; i++)
{
if (far_strstr(Card[pos]->data[i],Find_str)==NULL)
break;
}
if (i==5) /* 文字列が見つからなかった場合 */
return FALSE;
if (Find_zip[0]!=-1)
{
if (Card[pos]->zipcode[0]!=Find_zip[0])
return FALSE;
/* ↑↓郵便番号が不一致のとき */
if (Find_zip[1]!=-1 && Card[pos]->zipcode[1]!=Find_zip[1])
return FALSE;
}
Cardpos = pos;
card_reshow(63);
dp_putcardnum();
if (dp_errmes("データ発見 [ESC]中止 [それ以外]次へ")=='\033')
return TRUE;
else
return FALSE;
}
static void dp_find(void)
{
static struct SHEETSEL sel[2] =
{
{19,"前から後ろへ"},
{33,"後ろから前へ"},
};
static struct SHEETDAT sheet[5] =
{
{SHEET_VALUE1,"検索開始位置", 1,DUMMY,NULL },
{SHEET_VALUE1,"検索終了位置",SHEET_CREF(0),DUMMY,NULL },
{SHEET_STRING,"郵便番号" , 0, 6,DUMMY},
{SHEET_STRING,"文字列" , 0, 62,DUMMY},
{SHEET_SELECT,"順序" , 0, 2,sel },
};
int ret[5];
char zipbuf[7];
char strbuf[63];
unsigned i;
zipbuf[0] = strbuf[0] = '\0';
sheet[0].max = sheet[1].max = Cardnum;
sheet[2].pos = zipbuf;
sheet[3].pos = strbuf;
ret[0] = 1;
ret[1] = Cardnum;
ret[4] = 0;
if (!iscardexist() || !dp_sheetselect(SYSLINE_START,sheet,5,ret))
return;
Find_str = (char far *)strbuf;
switch (sscanf(zipbuf,"%u-%u",&Find_zip[0],&Find_zip[1]))
{
case -1:
case 0: Find_zip[0] = -1; break;
case 1: Find_zip[1] = -1; break;
}
if (ret[4]==0) /* 前から後ろへ(後方検索) */
for (i=ret[0]-1 ; i<ret[1] ; i++)
{
if (dpfind_sub(i))
return;
}
else /* 後ろから前へ(前方検索) */
for (i=ret[1]-1 ; i>ret[0] ; i--)
{
if (dpfind_sub(i))
return;
}
dp_errmes("データが見つかりません.");
}
/*---------------------------------------------------------------------------*/
void dp_datamenu(void)
{
static struct MENUDAT menu[] =
{
{'I',"挿入","現在のカード位置に空のカードを挿入します"},
{'D',"削除","カードを削除します"},
{'S',"ソート","カードを郵便番号でソートします"},
{'F',"検索","特定のデータを含むカードを検索します"},
};
int a = dp_menuselect("F5:データメニュー",4,menu);
switch (a)
{
case -1: break;
case 0: dp_insert(); break;
case 1: dp_delete(); break;
case 2: dp_sort(); break;
case 3: dp_find(); break;
}
}